package frontend.pages.reports.workperteam;

import backend.model.worklog.WorkLog;
import backend.service.worklog.WorkLogService;
import frontend.components.other.TeamSelectionPanel;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.reports.ReportInputUIModel;
import frontend.pages.reports.base.AbstractReportForm;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;

import java.util.List;

public class WorkPerTeamReportForm extends AbstractReportForm<WorkLog> {

    public static final String PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_TEAM = "pages.workPerTeamReport.form.team";

    public WorkPerTeamReportForm(String id, ReportInputUIModel model, List<WorkLog> reportResults, WebMarkupContainer workLogListContainer) {
        super(id, model, reportResults, workLogListContainer);
    }

    @Override
    protected void addAdditionalFilteringComponents() {
        Panel teamSelectionPanel = new TeamSelectionPanel("teamSelection", uiModel, null, PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_TEAM, false);
        add(teamSelectionPanel);
    }

    @Override
    protected List<WorkLog> retrieveReportDataFromDatabase() {
        WorkLogService workLogService = TimeTrackingWebApplication.getService(WorkLogService.class);
        List<WorkLog> workLogListFromDB = workLogService.loadWorkLogForTimeIntervalAndTeam(uiModel.getTeam(),
                uiModel.getStartDate(), uiModel.getEndDate());
        return workLogListFromDB;
    }

    @Override
    protected void doFormValidation() {
        super.doFormValidation();
        validateNotEmpty(uiModel.getTeam(), PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_TEAM);
    }
}
